package com.lagou.streamsink;

import org.apache.kudu.ColumnSchema;
import org.apache.kudu.Schema;
import org.apache.kudu.Type;
import org.apache.kudu.client.*;

import java.util.ArrayList;

public class CreateKuduTable {
    public static void main(String[] args) {
        KuduClient client = new KuduClient.KuduClientBuilder("hdp-2").build();
        ArrayList<ColumnSchema> columnSchemas = new ArrayList<>();
        ColumnSchema id = new ColumnSchema.ColumnSchemaBuilder("id", Type.STRING).key(true).build();
        ColumnSchema name = new ColumnSchema.ColumnSchemaBuilder("name", Type.STRING).key(false).build();
        ColumnSchema age = new ColumnSchema.ColumnSchemaBuilder("age", Type.INT32).key(false).build();
        columnSchemas.add(id);
        columnSchemas.add(name);
        columnSchemas.add(age);
        Schema schema = new Schema(columnSchemas);

        CreateTableOptions options = new CreateTableOptions();
        options.setNumReplicas(1);
        ArrayList<String> colRule = new ArrayList<>();
        colRule.add("id");
        options.addHashPartitions(colRule,3);

        try {
            client.createTable("user",schema,options);
//            KuduTable userTable = client.openTable("user");
//            Delete delete = userTable.newDelete();
//            PartialRow row = delete.getRow();
            KuduSession kuduSession = client.newSession();


        } catch (KuduException e) {
            e.printStackTrace();
        }finally {
            try {
                client.close();
            } catch (KuduException e) {
                e.printStackTrace();
            }
        }
    }
}
